﻿@model IEnumerable<MasPurchaseRegular>

@{
    ViewBag.Title = "ระเบียบการจัดซื้อ/จ้าง";
    ViewBag.Descr = "ข้อมูลระเบียบพัสดุ ที่ใช้สำหรับการซื้อ/จ้าง ในองค์กร";
}

@using (Html.BeginForm("DeleteAll", "MasPurchaseRegular", FormMethod.Post, new { id="form" }))
{
    @Html.AntiForgeryToken()
    
    <div class="row-fluid">    
        <div class="block-button-menu-above">
            @Html.ButtonAdd()
            @Html.ButtonDeleteAll()
        </div>

        @Html.ValidationSummary(true, "", new { @class = "alert alert-error" })

        <div class="row-fluid">
            <div class="table-header span12">
                <div class="span10">@ViewBag.Title</div>
				@Html.Partial("_ExportButton")
            </div>
        </div>

        <table id="table" class="table table-striped table-bordered table-hover" aria-describedby="table_info">
            <thead>
                <tr>
                    <th class="center" style="width:50px;">
                        <label>
                            <!-- Check box delete multiple records column-->
                            <input type="checkbox" />
                            <span class="lbl"></span>
                        </label>
                    </th>

                    <th>
                        @Html.DisplayNameFor(model => model.Name)
                    </th>

                    <th>
                        @Html.DisplayNameFor(model => model.Description)
                    </th>

                    <th class="center" style="width:80px;">
						<!-- Empty head column for export buttons -->&nbsp;
                    </th>
                </tr>
            </thead>

            <tbody>
                @foreach (var m in Model)
                {
                    <tr>
                        <td class="center">
                            <label>
                                <input type="checkbox" name="deleteIds" value="@(m.RegularId)" />
                                <span class="lbl"></span>
                            </label>
                        </td>

                        <td>@Html.ActionLink(@m.Name, "Details", new { Id=m.RegularId })</td>
                      
                        <td>@Html.DisplayFor(modelItem => m.Description)</td>
                
                        <td class="td-actions">
							@Html.Partial("_ButtonMenuEachRow", new ExportGrid
								{
									Id=m.RegularId, 
									DetailsUrl = Url.Action("Details") + "/" + m.RegularId,
									EditUrl = Url.Action("Edit") + "/" + m.RegularId,
									DeleteUrl = Url.Action("Delete") + "/" + m.RegularId,
									
								})
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
}

@section scripts {
	<script type="text/javascript">
		$(function () {
		    var oTable1 = $('#table').dataTable({
		        "aoColumns": [
                    { "bSortable": false },
                    null,
                    null,
                    { "bSortable": false }
		        ]
		    });

		    $('table th input:checkbox').on('click', function () {
		        var that = this;
		        $(this).closest('table').find('tr > td:first-child input:checkbox')
				.each(function () {
					this.checked = that.checked;
					$(this).closest('tr').toggleClass('selected');
				});
		    });

		    $('[data-rel=tooltip]').tooltip();

		    $("#form").submit(function () {
		        var currentForm = this;
		        bootbox.confirm(function(result) {
		            var _result = result;
		            if (result) {
		                $.ajax({
		                    url: "DeleteAll",
		                    type: "post",
		                    dataType: "json",
		                    data: $(currentForm).serialize(),
		                    success: function(result2) {
		                        if (result2.success) {
		                            location.reload();
		                        } else {
		                        }
		                    }
		                });
		            }
		        });
		        return false;
		    });
		})
	</script>
}